package com.gxa.meiye.admin.platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gxa.meiye.admin.platform.pojo.vo.AdminVo;
import com.gxa.meiye.admin.platform.pojo.vo.MenuVo;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

/**
 * @author bill
 * @date 2022/7/1 11:40
 */

@Component
public interface AdminMapper extends BaseMapper<AdminVo> {

    @Select("SELECT * FROM t_web_user WHERE account=#{account}")
    AdminVo queryAdminByName(String account);

    @Select("SELECT m.path\n" +
            "   FROM t_web_user u,t_web_role r,t_web_user_role ur,t_web_menu m,t_web_role_menu rm\n" +
            "   WHERE u.id=ur.user_id AND ur.role_id=r.id\n" +
            "   AND r.id=rm.role_id AND rm.menu_id=m.id\n" +
            "   AND u.name='张三' AND pow=1")
    Set<String> queryPerms(String account);

    @Select("SELECT id FROM t_web_user WHERE account=#{account} AND pwd=#{pwd}")
    Integer queryAdmin(AdminVo adminVo);

    @Select("SELECT id,name,pid,path\n" +
            "        FROM t_web_menu\n" +
            "        WHERE pow is NULL\n" +
            "        AND  id in(\n" +
            "                SELECT menu_id\n" +
            "                FROM t_web_role_menu\n" +
            "                WHERE role_id in (\n" +
            "                            SELECT role_id\n" +
            "                            FROM t_web_user_role\n" +
            "                            WHERE user_id=#{user_id})) AND pid IS NULL")
    List<MenuVo> selPMenu(Integer user_id);

    @Select("SELECT id,name,pid\n" +
            "        FROM t_web_menu\n" +
            "        WHERE pid=#{id} AND pow IS NULL")
    List<MenuVo> selSMenu(Integer id);

}
